4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
9 import javax.swing.DefaultComboBoxModel;
10 import javax.swing.GroupLayout;
11 import javax.swing.GroupLayout.Alignment;
12 import javax.swing.JButton;
13 import javax.swing.JComboBox;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JTextField;
18 import javax.swing.LayoutStyle.ComponentPlacement;
19 import javax.swing.SwingConstants;
20 import javax.swing.border.EmptyBorder;
22 import common.AdminInterface;
24 import configuration.___IntNames;
25 import domain.Districs;
26 import domain.HouseFeatures;
28 import domain.RuralHouse;
30 public class RequestNewHouseGUI extends JFrame {
35 private static final long serialVersionUID = 1L;
36 private JPanel contentPane;
38 private JLabel lblCode ;
39 private JLabel feedback = new JLabel("");
40 private JTextField Code_f;
41 private JLabel lblTown;
42 private JLabel lblDescription;
43 private JTextField description_f;
44 private JLabel lblKitchen;
45 private JTextField kitchens_f;
46 private JLabel lblRooms;
47 private JTextField rooms_f;
48 private JLabel lblLivings;
49 private JTextField lRooms_f;
50 private JLabel lblParkings;
51 private JTextField parkings_f;
52 private JLabel lblBaths;
53 private JTextField baths_f;
54 private JButton btnRegister;
55 private AdminInterface am = null;
56 private JComboBox<String> comboBox;
62 public RequestNewHouseGUI(Owner o) {
63 comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
64 Districs.longNames()));
66 am = (AdminInterface) Naming
67 .lookup(___IntNames.AdminManager);
68 } catch (Exception e1) {
69 System.out.println("Error accessing remote authentication: "
72 this.setTitle("New House");
73 setBackground(Color.WHITE);
74 this.getContentPane().setLayout(null);
76 setBounds(100, 100, 500, 583);
77 contentPane = new JPanel();
78 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
79 setContentPane(contentPane);
81 lblCode = new JLabel("House Name:");
82 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
84 Code_f = new JTextField();
85 Code_f.setColumns(10);
87 lblTown = new JLabel("District:");
88 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
90 lblDescription = new JLabel("Description(optional):");
91 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
93 description_f = new JTextField();
94 description_f.setToolTipText("");
95 description_f.setHorizontalAlignment(SwingConstants.LEFT);
96 description_f.setColumns(10);
98 lblKitchen = new JLabel("Kitchens:");
99 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
101 kitchens_f = new JTextField();
102 kitchens_f.setColumns(10);
104 lblRooms = new JLabel("Rooms:");
105 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
107 rooms_f = new JTextField();
108 rooms_f.setColumns(10);
110 lblLivings = new JLabel("Living rooms:");
111 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
113 lRooms_f = new JTextField();
114 lRooms_f.setColumns(10);
116 lblParkings = new JLabel("Parkings:");
117 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
119 parkings_f = new JTextField();
120 parkings_f.setColumns(10);
122 lblBaths = new JLabel("Baths:");
123 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
125 baths_f = new JTextField();
126 baths_f.setColumns(10);
128 btnRegister = new JButton("Request registration");
129 btnRegister.addActionListener(new ActionListener() {
130 public void actionPerformed(ActionEvent arg0) {
131 RuralHouse rh = null;
133 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
134 rh = new RuralHouse(Code_f.getText(),
135 owner, description_f.getText(),
136 (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()),
137 Integer.parseInt(kitchens_f.getText()),
138 Integer.parseInt(baths_f.getText()),
139 Integer.parseInt(lRooms_f.getText()),
140 Integer.parseInt(parkings_f.getText())) );
143 catch(NumberFormatException e){
148 if(am.addAdditionRequest(rh)){
149 feedback.setText("Request sended");
151 feedback.setText("Request cannot be sended(Already added)");
153 } catch (RemoteException e) {
154 // TODO Auto-generated catch block
163 GroupLayout gl_contentPane = new GroupLayout(contentPane);
164 gl_contentPane.setHorizontalGroup(
165 gl_contentPane.createParallelGroup(Alignment.LEADING)
166 .addGroup(gl_contentPane.createSequentialGroup()
167 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
168 .addGroup(gl_contentPane.createSequentialGroup()
170 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
171 .addGroup(gl_contentPane.createSequentialGroup()
172 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
173 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
174 .addGroup(gl_contentPane.createSequentialGroup()
175 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
177 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
178 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
179 .addGroup(gl_contentPane.createSequentialGroup()
180 .addComponent(lblLivings)
182 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
183 .addGroup(gl_contentPane.createSequentialGroup()
184 .addComponent(lblCode)
185 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
186 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
187 .addGroup(gl_contentPane.createSequentialGroup()
188 .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
190 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
192 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
193 .addComponent(lblDescription)
194 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
195 .addGroup(gl_contentPane.createSequentialGroup()
196 .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
198 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
199 .addGroup(gl_contentPane.createSequentialGroup()
200 .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
202 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
203 .addGroup(gl_contentPane.createSequentialGroup()
205 .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
206 .addPreferredGap(ComponentPlacement.UNRELATED)
207 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
208 .addGroup(gl_contentPane.createSequentialGroup()
210 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
211 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
212 .addComponent(btnRegister))))
213 .addContainerGap(97, Short.MAX_VALUE))
215 gl_contentPane.setVerticalGroup(
216 gl_contentPane.createParallelGroup(Alignment.LEADING)
217 .addGroup(gl_contentPane.createSequentialGroup()
219 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
220 .addGroup(gl_contentPane.createSequentialGroup()
222 .addComponent(lblDescription)
223 .addPreferredGap(ComponentPlacement.RELATED)
224 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
225 .addGroup(gl_contentPane.createSequentialGroup()
227 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
228 .addComponent(lblCode)
229 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
230 .addPreferredGap(ComponentPlacement.UNRELATED)
231 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
232 .addComponent(lblTown)
233 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
235 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
236 .addComponent(lblLivings)
237 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
239 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
240 .addGroup(gl_contentPane.createSequentialGroup()
242 .addComponent(lblRooms))
243 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
244 .addPreferredGap(ComponentPlacement.RELATED)
245 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
246 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
247 .addGroup(gl_contentPane.createSequentialGroup()
249 .addComponent(lblKitchen)))
250 .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
251 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
252 .addGroup(gl_contentPane.createSequentialGroup()
254 .addComponent(lblBaths))
255 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
257 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
258 .addComponent(lblParkings)
259 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
261 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
262 .addPreferredGap(ComponentPlacement.UNRELATED)
263 .addComponent(btnRegister)
266 contentPane.setLayout(gl_contentPane);